<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<%-- 引入页面头 --%>
<%@ include file="/pageHead.jsp"%>

<form name="form1" id="form1" action="" method="post">
	<div class="pageMain">
		<div class="pageTitle"><%=MessageResourcesUtils.getMessage(request, "systemmanage.servicemanagement.title") %><span></span><%=MessageResourcesUtils.getMessage(request, "dailyoperation.services.servicesList.title") %><span></span><%=MessageResourcesUtils.getMessage(request, "dailyoperation.services.servicesView.title") %></div>
		<div class="pageBody">
			<div class="form-group">
				<ul>
					<li>
						<i></i>
						<label><%=MessageResourcesUtils.getMessage(request, "dailyoperation.services.servicesList.servicenum") %></label>
						<span>${services.servicenum}</span>
					</li>
					<li>
						<i></i>
						<label><%=MessageResourcesUtils.getMessage(request, "dailyoperation.services.servicesList.servicename") %></label>
						<span>${services.servicename}</span>
					</li>
				</ul>
				<ul>
					<li>
						<i></i>
						<label><%=MessageResourcesUtils.getMessage(request, "dailyoperation.services.servicesList.remark") %></label>
						<span>${services.remark}</span>
					</li>
					
				</ul>
       		</div>
       		<!-- 分配服务菜单权限 start -->
			<div  style="border: 1px solid #e0e0e0;background:#fff;padding-top: 9px;height:350px;width: 99%;">
				<span style="padding-right: 18px"></span><%=MessageResourcesUtils.getMessage(request, "dailyoperation.services.servicesAdd.fenpeimenu") %>
	       		<div  style="margin-top: 9px;height:300px;overflow-y:auto;">
	       			<ul id="menuTree" class="ztree" style="padding-left: 15px;"></ul>
	       		</div>
       		</div>
			<!-- 分配服务菜单权限end -->
		</div>
		<div class="button-group" style="padding-top: 10px">
       			<input type="hidden"  name="id" id="id" value="${services.id}"/>
       			<input type="hidden"  name="menu_all" id="menu_all" value="${menu_all}"/>
       			<input type="hidden"  name="str_ids" id="str_ids" value="${str_ids}"/>
       			<input type="hidden"  name="menuids" id="menuids" value="${str_ids}"/>
       			<input type="button" class="btn btn-default"  id="butReturn" name="butReturn" value='<%=MessageResourcesUtils.getMessage(request, "common.button.back") %>' />
			</div>
	</div>
</form>

<script type="text/javascript">	
$(document).ready(function() {
	var treeArray;
	var treeAllArray;
	var zTree;
	
	function asyncMenu(event, treeId, treeNode, msg){
        var treeList=$("#str_ids").val();
        var treeAllList=$("#menu_all").val();
        var zTree = $.fn.zTree.getZTreeObj("menuTree");
        if(treeList != ""){
        	if(treeList.indexOf(",")>0){
				treeArray=treeList.split(",");
			}else{
				treeArray=new Array(treeList);	
			}
        	if(treeAllList.indexOf(",")>0){
				treeAllArray=treeAllList.split(",");
			}else{
				treeAllArray=new Array(treeAllList);	
			}
        }
		asyncMenuNodes(zTree.getNodes());
		if(treeArray != ""){
			for(var i=0;i<treeArray.length;i++){
				 var node = zTree.getNodeByParam("menuid",treeArray[i]);
				 if(node == null){
					 continue;
				 }
				 if(node.isParent){
					 continue;
				 }
				 zTree.checkNode(node, true, true);
				 zTree.updateNode(node); 
				 //当节点全部加载完成并且勾选后，再禁用，不允许用户勾选
				 if(i == treeArray.length - 1){
						for(var i =0;i<treeAllArray.length;i++){
							 var node = zTree.getNodeByParam("menuid",treeAllArray[i]);
							 if(node == null){
								 continue;
							 }
							 if(node.isParent){
								 continue;
							 }
							zTree.setChkDisabled(node, true, true, false);
						}
				  }
			}
			
		}
		
		
	}
	
	function asyncMenuNodes(nodes){
		if(!nodes) return;
		var zTree = $.fn.zTree.getZTreeObj("menuTree");
		for (var i=0, l=nodes.length; i<l; i++) {//遍历外层节点
			if (nodes[i].isParent && nodes[i].zAsync) {//如果是父节点并且父节点没有加载过
				asyncMenuNodes(nodes[i].children);//在这种条件下继续递归遍历该父节点的所有子节点
			} else {//如果不是父节点或者父节点已经加载过
				zTree.reAsyncChildNodes(nodes[i], "refresh", true);//清空后不展开父节点，其他值或缺省状态都自己展开
			}
		}
	}
	
	var menusetting = {
			async: {
				enable:true,
				url:"${systemctx}/dailyoperation/services/queryMenuDirectoryTree.json",
				autoParam: ["menucode","menuid","menulevel"]
			},check:{
				enable:true,
				chkStyle: "checkbox",
				chkDisabledInherit: true
			},data:{
				simpleData:{
					enable:true,
					idKey:"menucode",
					rootPid:0
				}
			},callback:{
				onAsyncSuccess:asyncMenu
			}
	};
	
	$.fn.zTree.init($("#menuTree"), menusetting);//初始化zTree，第三个参数没有则表明用异步加载
	zTree = $.fn.zTree.getZTreeObj("menuTree");

	$('#butReturn').click(function(){
		parent.document.location.reload();
	    $.fn.closeIssWindow();
	});
	
});
</script>
<%-- 引入页面尾 --%>
<%@ include file="/pageFloor.jsp"%>